<template>
  <el-container>
    <el-header class="login-one">
      <el-row>
        <el-col :span="8">
          <div style="margin-top: 10px">
            <img src="../assets/mlogo.png" width="30" height="30" style="border-radius: 100%" />
            <span style="font-size: larger;margin-top: 20px;">maets</span>
          </div>
        </el-col>
        <el-col :span="8">
          <div style="margin-top: 20px;margin-left: 350px;">
            欢迎<span style="color:crimson;font-size: 20px;font-weight: 500;">{{ username }}</span>登录
          </div>
        </el-col>
        <el-col :span="8">
          <div style="margin-top: 15px">
            <el-button type="danger" round @click="loginOut" size="small">
              <i class="el-icon-switch-button"></i>退出登录</el-button>
          </div>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu :default-openeds="['1']" router>
          <template v-for="x in permissionList">
            <el-submenu :index="x.permissionIndex">
              <template slot="title"><i :class="x.permissionIcon"></i>{{ x.label }}
              </template>
              <template v-for="y in x.childrenList">
                <el-menu-item :index="y.permissionUrl" style="padding-left: 60px;" :class="y.permissionIcon">{{ y.label }}</el-menu-item>
              </template>
            </el-submenu>
          </template>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main>
          <router-view />
        </el-main>
        <el-footer>
          Footer
        </el-footer>
      </el-container>
    </el-container>
  </el-container>
</template>
<script>
export default {
  name: "index",
  data() {
    return {
      username: "",
      permissionList: [
        {
          "permissionIndex": "1",
          "permissionIcon": "el-icon-s-custom",
          "label": "用户管理",
          "permissionUrl": "",
          "parentId": null,
          "nodeId": null,
          "childrenList": [
            {
              "permissionIndex": "2",
              "permissionIcon": "el-icon-s-custom",
              "label": "用户列表",
              "permissionUrl": "/index/userList",
              "parentId": 1,
              "nodeId": 2,
              "childrenList": null
            },
          ]
        }
      ],
    };
  },
  methods:{
    loginOut(){
      let _this=this;
      sessionStorage.clear();
      _this.$message.success("退出成功")
      _this.$router.push('/');

    },
    loadPermissionList(){
      let _this=this;
      this.$axios({
        method:'get',
        url:'permission/permissionList/'+this.username,

      }).then(res=>{
        _this.permissionList=res.data.data;
      }).catch(error=>{
       // alert("fail")
        _this.$message.error(error)
      })

    },

  },
  mounted() {
    this.username = sessionStorage.getItem('loginUsername');
    this.loadPermissionList();

  }
};
</script>

<style>
html,
body,
#app,
.el-container {
  height: 99.9%;
  margin-top: 0px;
}

.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.login-one {
  background-color: #1c77ac;
  background-repeat: no-repeat;
  overflow: hidden;
  height: 100%;
}

.el-main,
.el-footer {
  border: 1px blue solid;
}
</style>
